import pandas as pd
from fuzzywuzzy import fuzz
from pandas.core.frame import DataFrame

# file_name = '500万以上新开工项目情况表'
# file_name = '1000万以上项目情况表'
file_name = ''
df = pd.read_excel(rf'D:\Desktop\附件\{file_name}.xlsx',sheet_name='基础数据',header=0)
myset =set()

# 筛选
# f_df = df.loc[df['辅助列'] == 1]

f_df = df.loc[df['项目类型'] != '预备']
# f_df = df
f_df = f_df.loc[df['市州'] != '省直']


for i in f_df.index:
    myset.add(f_df['市州'].at[i])

print(type(f_df))

mydf = None
for v in myset:
    c_df = f_df.loc[df['市州'] == v]
    # if mydf is None:
    #     mydf =  c_df.sample(n=20, replace=False)
    # else:
    #     mydf = mydf._append(c_df.sample(n=20, replace=False), ignore_index=True)

    df_m=c_df.sample(n=20, replace=False)
    df_m=df_m.set_index('项目名称')
    df_m = df_m.fillna("")
    df_m = df_m.astype(str)

    df_m.to_excel(rf'D:\Desktop\附件\{file_name}\{v}.xlsx')

# mydf.to_excel(rf'D:\Desktop\附件\my1.xlsx')

# print(myset)
# print(f_df)
# c_df = df.sample(n=20, replace=False)
# result = df1.append(df2, ignore_index=True)

# print(c_df)


